package org.lc.stk.dao.question;

import java.util.List;

import org.lc.stk.model.question.attrs.DifficultySchema;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface DifficultySchemaRepository extends JpaRepository<DifficultySchema, Long> {
    
    /**
     * 检查名称是否存在（排除指定ID）
     */
    @Query("SELECT COUNT(s) > 0 FROM DifficultySchema s WHERE s.name = :name AND (:excludeId IS NULL OR s.id != :excludeId)")
    boolean existsByNameAndIdNot(
        @Param("name") String name,
        @Param("excludeId") Long excludeId
    );

    /**
     * 根据难度方案类型查询
     */
    @Query("SELECT s FROM DifficultySchema s WHERE s.type = :type")
    List<DifficultySchema> findByType(@Param("type") DifficultySchema.Type type);

    /**
     * 获取默认难度方案（四级制）
     */
    @Query("SELECT s FROM DifficultySchema s WHERE s.type = org.lc.stk.model.question.attrs.DifficultySchema.Type.FOUR_LEVEL ORDER BY s.id ASC")
    DifficultySchema findDefaultSchema();
}